
$( document ).ready(function(){
  $(document).ajaxSend(function(e, xhr, options) {
    var token = $("meta[name='csrf-token']").attr("content");
    xhr.setRequestHeader("X-CSRF-Token", token);
  });

  //
  // Begin Tweeting.
  // (mostly stolen from: http://github.com/seaofclouds/tweet/blob/master/tweet/jquery.tweet.js
  //
  if( $('#recent_tweets').length ){
    $("#recent_tweets").after('<div id="recent_tweets_loading" class="tweets-loading"><img src="/images/loading.gif" /> <span>Loading Tweets</span></div>');

    var url = document.location.protocol + '//twitter.com/favorites/harvest.json?count=3&callback=?';
    $.getJSON( url, function(data){
      tweets = (data.results || data);
      $.each(tweets, function(i,item){
        var from_user = item.from_user || item.user.screen_name;

        var text = item.text;
        var date = '<span><a href="http://twitter.com/'+from_user+'/statuses/'+item.id+'" title="view tweet on twitter" target="_blank">@' + from_user + ' ' +relative_time(item.created_at)+'</a></span>';
        $("#recent_tweets").append('<li>' + '<div>' + text + date + '</div>' + '</li>');
      });
      $("#recent_tweets_loading").hide();
      $("#recent_tweets").slideDown();
    });
  }
  //
  //  End Tweeting!
  //


  //
  // AnyStretch on Homepage image
  //
  if( $("#home-intro").length ){
    $("#home-intro-photo").anystretch("/images/intro-hyperakt.jpg");
  }

  //
  // New founders form
  //
  $("#new_founders_apply_button").click(function(e){
    e.preventDefault();
    $(this).hide();
    $("#new_founders_apply_form").slideDown("fast");
  });


  //
  // Begin Helpful?
  //
  window.helpful = {
    voting : false,
    vote_id : null,
    set_up : function(){
      $("#helpful input").change( helpful.vote );
    },
    vote : function(e){
      if(!helpful.voting){
        helpful.voting = true;
        var form = $(this).parents("form").first();
        var is_helpful = form.find("input:radio[name=is_helpful]:checked").val()=="true";

        $(this).siblings("label").addClass("selected");
        form.find("label:not(.selected)").fadeTo(0, .3);
        form.append('<div class="inline-loader" id="feedback_loader">saving response</div>');

        $.ajax({
          url:form.attr("action"),
          success: function(data){
            $("#helpful").hide();
            if( is_helpful ) helpful.thanks_feedback();
            else{
              helpful.vote_id = data.review.id;
              $("#feedback_comment").fadeIn("fast");
              $("#feedback_comment form").submit(helpful.submit_comment);
            }
          },
          error: function(){
            alert("We were unable to save your feedback. Please try again.");
            helpful.voting = false;
            form.find("label").fadeTo(1,1).removeClass("selected");
            $("#feedback_loader").remove();
          },
          data: { review:{ help_content_id:form.find("#help_id").val(), vote:is_helpful } },
          dataType: 'json',
          type: 'POST'
        });
      }
      else e.preventDefault();
    },
    submit_comment : function(e){
      e.preventDefault();

      if( $.trim( $("#feedback_comment_field").val() ).length ){
        $("#feedback_comment_submit").hide().after('<div style="margin-left: -15px;"><div class="inline-loader" id="feedback_comment_loader">sending response</div></div>');

        $.ajax({
          url: $("#feedback_comment form").first().attr("action") + "/" + helpful.vote_id,
          success : function(data){
            $("#feedback_comment").hide();
            helpful.thanks_feedback();
          },
          error : function(){
            alert("We were unable to save your feedback. Please try again.");
            $("#feedback_comment_loader").remove();
            $("#feedback_comment_submit").show();
          },
          data: { review: { comment: $("#feedback_comment_field").val() }, _method: "PUT" },
          dataType: 'json',
          type: 'POST'
        });
      }
      else{
        $("#feedback_comment").hide();
        helpful.thanks_feedback();
      }
    },
    thanks_feedback : function(){
      $("#feedback_thanks").fadeIn("fast");
      $("#feedback_thanks span").fadeOut("slow");
    }
  }
  if($("#helpful").length){
    helpful.set_up();
  }
  //
  // END Helpful

  //
  // Begin Sign In
  //
  window.sign_in = {
    set_up : function(modal){
      if(modal){
        if(typeof(_gat)=='object'){ _gaq.push(['_trackPageview', '/help/signin_modal']); }
        sign_in.set_up_validation();
      }
      else{
        if (!window._on_validation) window._on_validation = [];
        window._on_validation.push(function(){
          sign_in.set_up_validation();
        });
      }
      $("#forget_address").show();
      $("#signin-modal #forget_address a").first().click(sign_in.show_form);
    },
    set_up_validation : function(){
      $("#signin-modal #forget_form form").validate({
        errorElement: "em",
        submitHandler: sign_in.submit_form
      });
    },
    show_form : function(evt){
      if(evt) evt.preventDefault();

      if(typeof(_gat)=='object'){ _gaq.push(['_trackEvent', 'Sign In', 'Form Open']); }
      $("#forget_form_container").show();

      var newTop = $("#fancybox-wrap").offset().top - 50;
      $("#fancybox-wrap").stop().animate({ "top":  newTop + "px" }, "fast");

      $("#fancybox-content").stop().animate({'height':'270px'},"fast");
      $("#fancybox-content div").stop().first().animate({'height':'270px'},"fast");


      sign_in.switch_section("form");
    },
    submit_form : function(form){
      $("#forget_form_error").hide();

      if(typeof(_gat)=='object'){ _gaq.push(['_trackEvent', 'Sign In', 'Form Submit']); }

      var form = $("#forget_form form").first();
      var url = form.attr("action"); // + ".json";

      $("#help_document_submit").hide().after("<div id=\"forgot_loader\" style=\"line-height: 30px; height: 30px;\"><img src=\"/images/loading.gif\" style=\"vertical-align:middle;\" /></div>");

      $.ajax({
        url:url,
        success: function(data){
          if(typeof(_gat)=='object'){ _gaq.push(['_trackEvent', 'Sign In', 'Form Success']); }

          $("#forgot_email").text(data.email);
          sign_in.switch_section("success");
        },
        error: function(){
          if(typeof(_gat)=='object'){ _gaq.push(['_trackEvent', 'Sign In', 'Form Error']); }

          $("#forget_form p").first().html('Sorry, but we can&rsquo;t find this email address in our records. You can try another email address, or <a href="/help/contact/" class="errors-contact">contact Harvest Support</a> for help.').addClass("errors");
          $("#help_document_submit").show();
          $("#forgot_loader").remove();
        },
        data: form.serialize(),
        dataType: 'json',
        type: 'POST'
      });
    },
    switch_section : function(sec){
      $("#forget_address, #forget_success, #forget_form").hide();
      $("#forget_" + sec).show();
    }
  };
  if($("#signin-modal").length){
    sign_in.set_up();
  }
  if( $("#header_signup").find(".login").length ){
    if (!window._on_fancybox) window._on_fancybox = [];
    window._on_fancybox.push(function(){
      $("#header_signup").find("a.login").fancybox({
        'hideOnContentClick': false,
        'scrolling' : false,
        'autoDimensions' : false,
        'width' : 490,
        'height' : 180,
        'overlayColor' : '#000',
        'overlayOpacity' : 0.5,
        'padding' : 30,
        onComplete : function(){ sign_in.set_up(true); }
      });
    });
  }
  if($("#nav-sign-in").length){
    if (!window._on_fancybox) window._on_fancybox = [];
    window._on_fancybox.push(function(){
      $("#nav-sign-in").fancybox({
        'hideOnContentClick': false,
        'scrolling' : false,
        'autoDimensions' : false,
        'width' : 490,
        'height' : 180,
        'overlayColor' : '#000',
        'overlayOpacity' : 0.5,
        'padding' : 30,
        onComplete : function(){ sign_in.set_up(true); }
      });
    });
  }
  //
  // End Sign In
  //

  //
  // Begin API.
  //

  $('.currency-link').click(function(e){
    e.preventDefault();
    $('#currency-names').toggle();
  })

  //
  //  End API!
  //

  //
  //  Begin Support set-up / Validation
  //
  if( $("#support_contact").length ){

    if (!window._on_validation) window._on_validation = [];

    window._on_validation.push(function(){
      $("#support_contact form").validate({
        errorElement: "em",
        submitHandler: function(form){
          $(form).find(".form-submitted").show().siblings("input").hide();
          form.submit();
        }
      });
    });
  }
  //
  //  End Support Set-up / Validation
  //

  if( $(".em-link").length ){
    $(".em-link").each(function(){
      var link  = $(this).find("a");
      var base = link.attr("rel");
      link.removeAttr("rel");
      var dom = link.attr("href");
      var at = "@";

      var tot = base + at + dom.replace(/http:\/\//g,"");
      if(!link.text()) link.text( tot.replace(/%23/g,"") )
      tot = "mai%23lt%23o:" + tot;
      link.attr("href", tot.replace(/%23/g,"") );

      $(this).show();
    });
  }

  //
  //  Begin New Founders Set-up / Validation
  //
  if( $("#new_founders_app").length ){

    if (!window._on_validation) window._on_validation = [];

    window._on_validation.push(function(){
      $("#new_founders_app").validate({
        errorElement: "em",
        submitHandler: function(form){

          if( $("#recaptcha_response_field").length && !$("#recaptcha_response_field").val() ){
            alert("Please complete the Recaptcha field.");
            $("#recaptcha_response_field").focus();
            return false;
          }

          $(form).find(".form-submitted").show().siblings("input").hide();
          form.submit();
        }
      });
    });
  }
  //
  //  End New Founders Set-up / Validation
  //

  //
  //  Blog posts
  //
  if ($('#harvest_blog_posts').length) {

    $.getScript(document.location.protocol+'//www.google.com/jsapi?key=ABQIAAAA3xSo-atRte72KWaSRoKeTxSzkBHsDIJN_3AQ-JggceLos8trohQ7MtO6XNvzBDJNZR4r4H2E3Vsi2w');

    // Async _on_validation events.  Keep this at the bottom please.
    //
    window._no_google_rss_hits = 0;

    window._google_rss_checker = setInterval(function(){
      if (typeof google == 'object') {
        google.load("feeds", "1", { 'callback': function(){
          var feed = new google.feeds.Feed(document.location.protocol+"//www.getharvest.com/blog/feed/");
          feed.setNumEntries(4);

          feed.load(function(result) {
            if (!result.error) {
              $.each(result.feed.entries, function(){
                this.publishedDate = this.publishedDate.slice(5, 16);
                // Only show the "New Feature" category
                var li = $(document.createElement('li'));
                var link = $(document.createElement('a'));
                link.attr('href', this.link);
                link.html(this.title);
                link.appendTo( li );
                var span = $(document.createElement('span'));
                span.html(this.publishedDate);
                span.appendTo( li );
                if ($.inArray('New Features', this.categories) > -1) {
                  var fspan = $(document.createElement('span'));
                  fspan.attr('class', 'feature');
                  fspan.html('New Feature');
                  fspan.appendTo( li );
                }
                li.appendTo( '#harvest_blog_posts' );
              });
            }
          });
        }});
        clearTimeout(window._google_rss_checker);
      } else {
        window._no_google_rss_hits++;
      }
      if (window._no_google_rss_hits > 50) {
        clearTimeout(window._google_rss_checker);
      }
    }, 25);

  }
  //
  //  End blog posts
  //

  if( $('.help-search-box input[type="text"]').length ){
    $('.help-search-box input[type="text"]').each(function(){
      $(this).data("defaultText", $(this).val());
    });
    $('.help-search-box input[type="text"]').focus(function(){
      if(typeof(_gat)=='object'){ _gaq.push(['_trackEvent', 'Search', 'Search Field Focus']); }
      if($(this).val()==$(this).data("defaultText")) $(this).val("");
      $(this).addClass("typing");
    });
    $('.help-search-box input[type="text"]').blur(function(){
      var val = $(this).val();
      val = $.trim( val );
      if(!val.length){
        $(this).val($(this).data("defaultText"));
        $(this).removeClass("typing");
      }
    });
  }

  //
  //  Search
  //
  if ($('.instant-search').length) {
    window.instant_searching = false;

    $('.instant-search').each(function(){
        var last_term = null;
        var search_el = $(this);
        var result_el = $('#'+search_el.attr('rel'));

        if (result_el) {

          var search = function(evt){
            var search_el = $(evt.target);
            var easter_reg = new RegExp('^(gir|ape|doug|orangu)');

            if(evt.which == 40 && result_el.is(':visible') && result_el.find("ul") ){
              search_el.blur();
              search_results.highlight();
            }
            else if ( $.trim( search_el.val() ).length > 2 && search_el.val() != last_term && search_el.val() != search_el.data("defaultText") ){
                    if ( !window.instant_searching ) {
                      last_term = search_el.val();
                      window.instant_searching = true;

                        search_results.show(result_el);

                        if(easter_reg.test(last_term)){
                          var easter_src;
                          var div = $("<div />", { "class": "easteregg" });
                          if(last_term[0]==="g"){easter_src = "/images/giraffe.jpg";}
                          else if(last_term[0]==="a" || last_term[0]==="o"){easter_src = "/images/orangutang.jpg";}
                          else {easter_src = "/images/doug.gif";}
                          div.html($("<img />", { src: easter_src }) );
                          result_el.html(div);
                          window.instant_searching = false;
                        }
                        else{
                          jQuery.getJSON(
                            $('#search_target_url').val(),
                            search_el.parent('form').serialize(),
                            function(data){

                              if (data && data.length > 0){

                                var ul = $(document.createElement('ul'));
                                ul.addClass("help-doc-list");

                                $.each(data, function(){
                                  search_results.add(this, ul);
                                });

                                result_el.html(ul);
                              }
                              else {
                                result_el.html('<span class="error">Sorry, no results found for <b>&ldquo;' + $.trim( search_el.val() ) + '.&rdquo;</b></span>');
                              }

                              window.instant_searching = false;
                            }
                          );
                        }
                    }
            }
            else if( search_el.val() != last_term ) {
              last_term = null;
              search_results.hide(result_el);
            }

          };

          var search_results = {
            current : null,
            show : function(result_el){
              $("#search_mag").hide();
              $("#search_x").show();
              result_el.show();
            },
            hide : function(result_el){
              $("#search_x").hide();
              $("#search_mag").show();
              search_results.current = null;
              result_el.hide();
            },
            add : function(obj, ul){
              var li = $(document.createElement('li'));
              var link = $(document.createElement('a'));
              link.attr('href', obj.url);
              link.html('<span class="title">'+obj.title+'</span><span class="excerpt">'+obj.excerpt+'</span>');
              if (obj.unpublished)
                link.find(".title").addClass("unpublished");
              if (obj.is_video)
                link.find(".title").addClass("video");
              link.appendTo( li );
              link.click(function(e){
                e.preventDefault();
                search_results.goto_link($(this).attr("href"));
              });
              li.appendTo( ul );
            },
            highlight : function(){
              search_results.current = 0;
              result_el.find("ul li").first().find("a").addClass('highlight');
              $(document).keydown(search_results.move_highlight);
            },
            next_highlight : function() {
              var cur = search_results.current;
              if( cur < result_el.find("ul li").length - 1 ){
                result_el.find("ul li:eq("+cur+") a").removeClass("highlight");
                cur ++;
                result_el.find("ul li:eq("+cur+") a").addClass("highlight");
              }
              search_results.current = cur;
            },
            prev_highlight : function() {
              var cur = search_results.current;
              if( cur > 0 ){
                result_el.find("ul li:eq("+cur+") a").removeClass("highlight");
                cur --;
                result_el.find("ul li:eq("+cur+") a").addClass("highlight");
              }
              else if ( cur == 0 ) search_results.stop_highlight();
              search_results.current = cur;
            },
            move_highlight : function(evt) {
              if(evt.which == 40) {
                evt.preventDefault();
                search_results.next_highlight();
              }
              else if(evt.which == 38) {
                evt.preventDefault();
                search_results.prev_highlight();
              }
              else if(evt.which == 39 || evt.which == 13){
                evt.preventDefault();
                url = result_el.find("ul li:eq("+search_results.current+") a").attr("href");
                search_results.goto_link(url);
              }
            },
            goto_link : function(url) {
              if(typeof createCookie == "function") createCookie('source_search_path', '/help/search?'+search_el.parent('form').serialize(), 2);
              window.location = url;
            },
            stop_highlight : function(){
              if(search_results.current >= 0) result_el.find("ul li:eq("+search_results.current+") a").removeClass("highlight");
              search_results.current = null;
              $(document).unbind('keydown', search_results.move_highlight);
              search_el.focus();
            }
          };

          $("#search_x").click(function(e){
            e.preventDefault();
            search_el.val("");
            $(this).siblings(".instant-search").first().blur();
          });

          search_el.keyup(search);
          search_el.blur(search);
          search_el.parent('form').submit(function(evt){search(evt); evt.stopPropagation(); return false});

        }

    });

  }
  //
  //  End search
  //

});


function relative_time(time_value) {
  var values = time_value.split(" ");
  time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
  var parsed_date = Date.parse(time_value);
  var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
  var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
  delta = delta + (relative_to.getTimezoneOffset() * 60);

  if (delta < 60) {
    return 'less than a minute ago';
  } else if(delta < 120) {
    return 'a minute ago';
  } else if(delta < (60*60)) {
    return (parseInt(delta / 60)).toString() + ' minutes ago';
  } else if(delta < (120*60)) {
    return 'an hour ago';
  } else if(delta < (24*60*60)) {
    return (parseInt(delta / 3600)).toString() + ' hours ago';
  } else if(delta < (48*60*60)) {
    return '1 day ago';
  } else {
    return (parseInt(delta / 86400)).toString() + ' days ago';
  }
}

// Async _on_validation events.  Keep this at the bottom please.
//
window._no_validation_hits = 0;

window._validation_checker = setInterval(function(){
  if (typeof $ == 'function' && typeof $.fn.validate == 'function') {
    if (window._on_validation && window._on_validation.length > 0) {
      while (call = window._on_validation.shift()) {
        call.apply();
      }
    } else {
      window._no_validation_hits++;
    }
    if (window._no_validation_hits > 50) {
      clearTimeout(window._validation_checker);
    }
  }
}, 25);

// Async _on_validation events.  Keep this at the bottom please.
//
window._no_fancybox_hits = 0;

window._fancybox_checker = setInterval(function(){
  if (typeof $ == 'function' && typeof $.fn.fancybox == 'function') {
    if (window._on_fancybox && window._on_fancybox.length > 0) {
      while (call = window._on_fancybox.shift()) {
        call.apply();
      }
    } else {
      window._no_fancybox_hits++;
    }
    if (window._no_fancybox_hits > 50) {
      clearTimeout(window._fancybox_checker);
    }
  }
}, 25);


//
// Symbolset
// www.symbolset.com
// Copyright © 2012 Oak Studios LLC
//
if (/(MSIE [7-9]\.|Opera.*Version\/(10\.[5-9]|(11|12)\.)|Chrome\/([1-9]|10)\.|Version\/[2-4][\.0-9]+ Safari\/|Version\/(4\.0\.[4-9]|4\.[1-9]|5\.0)[\.0-9]+? Mobile\/.*Safari\/|Android [1-2]\.)/.test(navigator.userAgent)) {

  var ss_set={'github octocat':'\uF671','googleplus':'\uF613','foursquare':'\uF690','thumbs up':'\uD83D\uDC4D','wordpress':'\uF621','posterous':'\uF623','pinterest':'\uF650','instagram':'\uF641','linkedin':'\uF612','thumbsup':'\uD83D\uDC4D','dribbble':'\uF660','facebook':'\uF610','envelope':'\u2709','rss feed':'\uDB8C\uDC20','behance':'\uF661','twitter':'\uF611','octocat':'\uF671','youtube':'\uF630','google+':'\uF613','spotify':'\uF6B1','approve':'\uD83D\uDC4D','last fm':'\uF6B2','blogger':'\uF622','paypal':'\uF680','flickr':'\uF640','github':'\uF670','tumblr':'\uF620','lastfm':'\uF6B2','email':'\u2709','vimeo':'\uF631','skype':'\uF6A0','mail':'\u2709','like':'\uD83D\uDC4D','rdio':'\uF6B0','rss':'\uE310'};

  if (typeof ss_icons !== 'object' || typeof ss_icons !== 'object') {
    var ss_icons = ss_set;
    var ss_keywords = [];
    for (var i in ss_set) { ss_keywords.push(i); };
  } else {
    for (var i in ss_set) { ss_icons[i] = ss_set[i]; ss_keywords.push(i); }
  };

  if (typeof ss_legacy !== 'function') {

    /* domready.js */
    !function(a,b){typeof module!="undefined"?module.exports=b():typeof define=="function"&&typeof define.amd=="object"?define(b):this[a]=b()}("ss_ready",function(a){function m(a){l=1;while(a=b.shift())a()}var b=[],c,d=!1,e=document,f=e.documentElement,g=f.doScroll,h="DOMContentLoaded",i="addEventListener",j="onreadystatechange",k="readyState",l=/^loade|c/.test(e[k]);return e[i]&&e[i](h,c=function(){e.removeEventListener(h,c,d),m()},d),g&&e.attachEvent(j,c=function(){/^c/.test(e[k])&&(e.detachEvent(j,c),m())}),a=g?function(c){self!=top?l?c():b.push(c):function(){try{f.doScroll("left")}catch(b){return setTimeout(function(){a(c)},50)}c()}()}:function(a){l?a():b.push(a)}})

    var ss_legacy = function(node) {

      if (!node instanceof Object) return false;

      if (node.length) {
        for (var i=0; i<node.length; i++) {
          ss_legacy(node[i]);
        }
        return;
      };

      if (node.value) {
        node.value = ss_liga(node.value);
      } else if (node.nodeValue) {
        node.nodeValue = ss_liga(node.nodeValue);
      } else if (node.innerHTML) {
        node.innerHTML = ss_liga(node.innerHTML);
      }

    };

    var ss_getElementsByClassName = function(node, classname) {
      var a = [];
      var re = new RegExp('(^| )'+classname+'( |$)');
      var els = node.getElementsByTagName("*");
      for(var i=0,j=els.length; i<j; i++)
          if(re.test(els[i].className))a.push(els[i]);
      return a;
    };

    var ss_liga = function(that) {
      var re = new RegExp(ss_keywords.join('|').replace(/[-[\]{}()*+?.,\\^$#\s]/g, "\\$&"),"gi");
      return that.replace(re, function(v) {
        return ss_icons[v.toLowerCase()];
      });
    };

    ss_ready(function() {
      if (document.getElementsByClassName) {
        ss_legacy(document.getElementsByClassName('ss-social-circle'));
      } else {
        ss_legacy(ss_getElementsByClassName(document.body, 'ss-social-circle'));
      }
    });

  }

};
if (/(MSIE [7-9]\.|Opera.*Version\/(11|12)\.|Chrome\/([5-9]|10)\.|Version\/(4)[\.0-9]+ Safari\/|Version\/(4|5\.0)[\.0-9]+? Mobile\/.*Safari\/)/.test(navigator.userAgent)) {

  if (typeof ss_legacy !== 'function') {

    /* domready.js */
    !function(a,b){typeof module!="undefined"?module.exports=b():typeof define=="function"&&typeof define.amd=="object"?define(b):this[a]=b()}("ss_ready",function(a){function m(a){l=1;while(a=b.shift())a()}var b=[],c,d=!1,e=document,f=e.documentElement,g=f.doScroll,h="DOMContentLoaded",i="addEventListener",j="onreadystatechange",k="readyState",l=/^loade|c/.test(e[k]);return e[i]&&e[i](h,c=function(){e.removeEventListener(h,c,d),m()},d),g&&e.attachEvent(j,c=function(){/^c/.test(e[k])&&(e.detachEvent(j,c),m())}),a=g?function(c){self!=top?l?c():b.push(c):function(){try{f.doScroll("left")}catch(b){return setTimeout(function(){a(c)},50)}c()}()}:function(a){l?a():b.push(a)}})

    var ss_legacy = function(node) {

      if (!node instanceof Object) return false;

      if (node.length) {
        for (var i=0; i<node.length; i++) {
          ss_legacy(node[i]);
        }
        return;
      };

      if (node.value) {
        node.value = ss_liga(node.value);
      } else if (node.nodeValue) {
        node.nodeValue = ss_liga(node.nodeValue);
      } else if (node.innerHTML) {
        node.innerHTML = ss_liga(node.innerHTML);
      }

    };

    var ss_getElementsByClassName = function(node, classname) {
      var a = [];
      var re = new RegExp('(^| )'+classname+'( |$)');
      var els = node.getElementsByTagName("*");
      for(var i=0,j=els.length; i<j; i++)
          if(re.test(els[i].className))a.push(els[i]);
      return a;
    };

    var ss_liga = function(that) {
      var re = new RegExp(ss_keywords.join('|'),"gi");
      return that.replace(re, function(v) {
        return ss_icons[v.toLowerCase()];
      });
    };

    ss_ready(function() {
      if (document.getElementsByClassName) {
        ss_legacy(document.getElementsByClassName('ss-icon'));
      } else {
        ss_legacy(ss_getElementsByClassName(document.body, 'ss-icon'));
      }
    });

  }

  var ss_set={'notifications disabled':'\uD83D\uDD15','notificationsdisabled':'\uD83D\uDD15','notification disabled':'\uD83D\uDD15','notificationdisabled':'\uD83D\uDD15','telephone disabled':'\uE300','telephonedisabled':'\uE300','writing disabled':'\uE071','pencil disabled':'\uE071','calendar remove':'\uF071','remove calendar':'\uF071','writingdisabled':'\uE071','calendar check':'\uF072','pencildisabled':'\uE071','removecalendar':'\uF071','cloud download':'\uEB00','navigate right':'\u25BB','calendarremove':'\uF071','phone disabled':'\uE300','medium battery':'\uEA11','check calendar':'\uF072','battery medium':'\uEA11','female avatar':'\uD83D\uDC67','mediumbattery':'\uEA11','phonedisabled':'\uE300','navigateright':'\u25BB','navigate left':'\u25C5','call disabled':'\uE300','notifications':'\uD83D\uDD14','empty battery':'\uEA13','bell disabled':'\uD83D\uDD15','checkcalendar':'\uF072','clouddownload':'\uEB00','shopping cart':'\uE500','navigate down':'\uF501','batterymedium':'\uEA11','battery empty':'\uEA13','calendarcheck':'\uF072','emptybattery':'\uEA13','femaleavatar':'\uD83D\uDC67','navigatedown':'\uF501','battery high':'\uEA10','shoppingcart':'\uE500','rotate right':'\u21BB','battery full':'\uD83D\uDD0B','mobile phone':'\uD83D\uDCF1','add calendar':'\uF070','full battery':'\uD83D\uDD0B','skip forward':'\u23ED','fast forward':'\u23E9','cloud upload':'\uEB40','belldisabled':'\uD83D\uDD15','navigateleft':'\u25C5','batteryempty':'\uEA13','notification':'\uD83D\uDD14','high battery':'\uEA10','calldisabled':'\uE300','calendar add':'\uF070','credit card':'\uD83D\uDCB3','battery low':'\uEA12','batteryfull':'\uD83D\uDD0B','rotateright':'\u21BB','information':'\u2139','addcalendar':'\uF070','photographs':'\uD83C\uDF04','calendaradd':'\uF070','mobilephone':'\uD83D\uDCF1','rotate left':'\u21BA','male avatar':'\uD83D\uDC64','skipforward':'\u23ED','batteryhigh':'\uEA10','low battery':'\uEA12','fastforward':'\u23E9','female user':'\uD83D\uDC67','thumbs down':'\uD83D\uDC4E','highbattery':'\uEA10','cloudupload':'\uEB40','videocamera':'\uD83D\uDCF9','volume high':'\uD83D\uDD0A','high volume':'\uD83D\uDD0A','fullbattery':'\uD83D\uDD0B','navigate up':'\uF500','remove date':'\uF071','navigation':'\uE670','femaleuser':'\uD83D\uDC67','cell phone':'\uD83D\uDCF1','screenshot':'\u2316','down right':'\u2B0A','directions':'\uE672','rotateleft':'\u21BA','disapprove':'\uD83D\uDC4E','eyedropper':'\uE200','check date':'\uF072','thumbsdown':'\uD83D\uDC4E','visibility':'\uD83D\uDC40','attachment':'\uD83D\uDCCE','creditcard':'\uD83D\uDCB3','microphone':'\uD83C\uDFA4','removedate':'\uF071','connection':'\uEB85','volume low':'\uD83D\uDD09','lowbattery':'\uEA12','low volume':'\uD83D\uDD09','volumehigh':'\uD83D\uDD0A','smartphone':'\uD83D\uDCF1','highvolume':'\uD83D\uDD0A','half heart':'\uE1A0','maleavatar':'\uD83D\uDC64','navigateup':'\uF500','pull quote':'\u201C','photograph':'\uD83C\uDF04','batterylow':'\uEA12','male user':'\uD83D\uDC64','pullquote':'\u201C','dashboard':'\uF000','musicnote':'\u266B','skip back':'\u23EE','stopwatch':'\u23F1','checkmark':'\u2713','crosshair':'\u2316','cellphone':'\uD83D\uDCF1','down left':'\u2B0B','pie chart':'\uE570','bar chart':'\uD83D\uDCCA','volumelow':'\uD83D\uDD09','lowvolume':'\uD83D\uDD09','telephone':'\uD83D\uDCDE','checkdate':'\uF072','half star':'\uE1A1','briefcase':'\uD83D\uDCBC','halfheart':'\uE1A0','thumbs up':'\uD83D\uDC4D','backspace':'\u232B','downright':'\u2B0A','paperclip':'\uD83D\uDCCE','envelope':'\u2709','database':'\uE7A0','barchart':'\uD83D\uDCCA','add date':'\uF070','skipback':'\u23EE','maleuser':'\uD83D\uDC64','location':'\uE6D0','facetime':'\uE320','end call':'\uE300','signpost':'\uE672','notebook':'\uD83D\uDCD3','dropdown':'\u25BE','halfstar':'\uE1A1','favorite':'\u22C6','subtract':'\u002D','computer':'\uD83D\uDCBB','settings':'\u2699','thumbsup':'\uD83D\uDC4D','bookmark':'\uD83D\uDD16','keywords':'\uE100','trashcan':'\uE0D0','previous':'\u25C5','pictures':'\uD83C\uDF04','download':'\uEB01','insecure':'\uD83D\uDD13','unlocked':'\uD83D\uDD13','up right':'\u2B08','navigate':'\uE670','downleft':'\u2B0B','question':'\u2753','contract':'\uEE01','calendar':'\uD83D\uDCC6','document':'\uD83D\uDCC4','piechart':'\uE570','typeface':'\uED01','upright':'\u2B08','forward':'\u27A1','airplay':'\uE800','picture':'\uD83C\uDF04','checked':'\u2713','shuffle':'\uD83D\uDD00','windows':'\uE202','compose':'\uD83D\uDCDD','retweet':'\uF600','columns':'\uE9A2','desktop':'\uD83D\uDCBB','adddate':'\uF070','display':'\uD83D\uDCBB','monitor':'\uD83D\uDCBB','package':'\uD83D\uDCE6','approve':'\uD83D\uDC4D','private':'\uD83D\uDD12','dictate':'\uD83C\uDFA4','caution':'\u26D4','warning':'\u26A0','refresh':'\u21BB','visible':'\uD83D\uDC40','battery':'\uD83D\uDD0B','speaker':'\uD83D\uDD08','dislike':'\uD83D\uDC4E','syncing':'\uEB82','loading':'\uEB83','avatars':'\uD83D\uDC65','up left':'\u2B09','comment':'\uD83D\uDCAC','printer':'\u2399','endcall':'\uE300','keyword':'\uE100','compass':'\uE671','pencil':'\u270E','photos':'\uD83C\uDF04','eraser':'\u2710','volume':'\uD83D\uDD08','cursor':'\uE001','videos':'\uD83D\uDCF9','upleft':'\u2B09','locate':'\uE670','locked':'\uD83D\uDD12','laptop':'\uEA00','tablet':'\uEA01','remove':'\u002D','hyphen':'\u002D','attach':'\uD83D\uDCCE','record':'\u25CF','upload':'\uEB41','iphone':'\uD83D\uDCF1','mobile':'\uD83D\uDCF1','rewind':'\u23EA','avatar':'\uD83D\uDC64','target':'\u25CE','sample':'\uE200','secure':'\uD83D\uDD12','delete':'\u2421','unlock':'\uD83D\uDD13','layers':'\uE202','camera':'\uD83D\uDCF7','expand':'\u2922','action':'\uEE00','repeat':'\uD83D\uDD01','layout':'\uEDA0','folder':'\uD83D\uDCC1','tagged':'\uE100','search':'\uD83D\uDD0E','public':'\uD83D\uDD13','images':'\uD83C\uDF04','replay':'\u21BA','timer':'\u23F1','print':'\u2399','quote':'\u201C','write':'\u270E','erase':'\u2710','right':'\u27A1','trash':'\uE0D0','heart':'\u2665','share':'\uEE00','visit':'\uEE00','nodes':'\uEB85','zelda':'\uE1A0','cloud':'\u2601','phone':'\uD83D\uDCDE','reply':'\u21A9','email':'\u2709','alert':'\u26A0','merge':'\uEB81','inbox':'\uD83D\uDCE5','users':'\uD83D\uDC65','globe':'\uD83C\uDF0E','earth':'\uD83C\uDF0E','minus':'\u002D','world':'\uD83C\uDF0E','clock':'\u23F2','music':'\u266B','check':'\u2713','audio':'\u266B','eject':'\u23CF','sound':'\uD83D\uDD08','close':'\u2421','image':'\uD83C\uDF04','photo':'\uD83C\uDF04','video':'\uD83D\uDCF9','pause':'\uE8A0','call':'\uD83D\uDCDE','play':'\u25B6','bell':'\uD83D\uDD14','view':'\uD83D\uDC40','stop':'\u25A0','skip':'\u23ED','back':'\u2B05','undo':'\u21BA','grid':'\uE9A0','rows':'\uE9A1','time':'\u23F2','left':'\u2B05','text':'\uED00','look':'\uD83D\uDC40','date':'\uD83D\uDCC6','ipad':'\uEA01','cell':'\uD83D\uDCF1','link':'\uD83D\uDD17','home':'\u2302','down':'\u2B07','cart':'\uE500','plus':'\u002B','user':'\uD83D\uDC64','talk':'\uD83D\uDCAC','chat':'\uD83D\uDCAC','fork':'\uEB80','redo':'\u21BB','mail':'\u2709','info':'\u2139','move':'\uE070','gear':'\u2699','sync':'\uEB82','crop':'\uE201','star':'\u22C6','work':'\uD83D\uDCBC','help':'\u2753','wifi':'\uEB84','love':'\u2665','list':'\uED50','like':'\uD83D\uDC4D','next':'\u25BB','flag':'\u2691','tags':'\uE100','page':'\uD83D\uDCC4','file':'\uD83D\uDCC4','lock':'\uD83D\uDD12','font':'\uED01','box':'\uD83D\uDCE6','ban':'\uD83D\uDEAB','tag':'\uE100','out':'\uEE00','fax':'\uD83D\uDCE0','rss':'\uE310','key':'\uD83D\uDD11','add':'\u002B','map':'\uE673','pin':'\uD83D\uDCCD','mic':'\uD83C\uDFA4','eye':'\uD83D\uDC40','cog':'\u2699','up':'\u2B06'};

  if (typeof ss_icons !== 'object' || typeof ss_icons !== 'object') {
    var ss_icons = ss_set;
    var ss_keywords = [];
    for (var i in ss_set) { ss_keywords.push(i); };
  } else {
    for (var i in ss_set) { ss_icons[i] = ss_set[i]; ss_keywords.push(i); }
  };

};

if (window.location.search.indexOf("generate_squash_error=true") != -1) {
  error = new Error("Test JavaScript error!");
  error._squash_user_data = {
    date: (new Date())
  };
  throw(error);
};